package 刷题10月.二叉树;
// https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/solution/mian-shi-ti-55-i-er-cha-shu-de-shen-du-xian-xu-bia/
public class 面试题55I二叉树的深度1008 {

      public class TreeNode {
          int val;
          TreeNode left;
          TreeNode right;
          TreeNode(int x) { val = x; }
      }

    class Solution {
        //dfs 栈和递归
        public int maxDepth(TreeNode root) {
            if(root == null) return 0;
            return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
        }
        //队列bfs
        // public int maxDepth(TreeNode root) {
        //     if (root == null) return 0;
        //     Queue<TreeNode> queue = new LinkedList<>();
        //     queue.add(root);
        //     int res = 0;
        //     while (!queue.isEmpty()) {
        //         res++;
        //         int n = queue.size();
        //         for (int i = 0; i < n; i++) {
        //             TreeNode node = queue.poll();
        //             if (node.left != null) queue.add(node.left);
        //             if (node.right != null) queue.add(node.right);
        //         }
        //     }
        //     return res;
        // }

    }
}
